package com.fromfuture.xuhuidoc.android.fragments;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.fromfuture.xuhuidoc.R;
import com.fromfuture.xuhuidoc.android.base.MyWebview;

/**
 * Author：何送军
 * creation time：2017/8/26
 **/
public class MyYuYueFragment extends Fragment {

    private String weburl;
    private String channelName;

    private View rootview;
    private MyWebview webview;

    Handler handler=new Handler();

    @Override
    public void onAttach(Activity activity) {
        // TODO Auto-generated method stub
        super.onAttach(activity);
    }

    private View view;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        rootview=inflater.inflate(R.layout.fragment_my_yuyue,container,false);
        init();
        return rootview;
    }
    @Override
    public void setArguments(Bundle bundle) {
        // TODO Auto-generated method stub
        weburl=bundle.getString("weburl");
        channelName=bundle.getString("name");

    }
    private void init(){
        webview= (MyWebview) rootview.findViewById(R.id.myyuyue_webview);
        webviewback();
        webview.loadUrl(weburl);
    }

    private void webviewback(){

        webview.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
                    if (webview != null && webview.canGoBack()) {
                        webview.goBack();
                    } else {
                        getActivity().onBackPressed();
                    }
                    return true;
                }
                return  false;
            }
        });

    }

}
